#include "firplayer.h"

FIRMove FIRPersonPlayer::GenerateMove( Byte matrix[15][15] )
{
    FIRRenderer::Instance().EnableUserControl();

    MSG msg;
    while(GetMessage(&msg, NULL, 0, 0)) {
        if (MSG_CHESSDOWN == msg.message) break;
    }

    FIRMove move = *(reinterpret_cast<FIRMove*>(&msg.lParam));

    FIRRenderer::Instance().DisableUserControl();
    return move;
}

FIRPersonPlayer::FIRPersonPlayer( FIRChessType t )
{
    sign = t;
}

FIRMove FIRComputerPlayer::GenerateMove( Byte matrix[15][15] )
{
    // generate a move from plugin
    FIRMove last_firmove = FIRManager::Instance().GetLastMove();
    Move last_move = {last_firmove.x, last_firmove.y};
    Move move = ai_plugin->GenerateMove(matrix, last_move);
    FIRMove new_fir_move = {move.x, move.y};

    FIRRenderer::Instance().DrawChessman(move.x, move.y, sign);

    return new_fir_move;
}

FIRComputerPlayer::FIRComputerPlayer( FIRChessType t ) : ai_plugin(0)
{
    sign = t;
}

FIRComputerPlayer::~FIRComputerPlayer()
{
    delete ai_plugin;
}

void FIRComputerPlayer::SetAIPlugin( IAIPlugin* plugin )
{
    if (ai_plugin) delete ai_plugin;
    ai_plugin = plugin;
}

FIRMove FIRNetworkPlayer::GenerateMove( Byte matrix[15][15] )
{
    return FIRMove();
}

FIRNetworkPlayer::FIRNetworkPlayer( FIRChessType t )
{
    sign = t;
}

FIRChessType FIRPlayer::GetChessType()
{
    return sign;
}